package com.bolt.support.spring.jpa.jpql;

import com.bolt.common.reflect.ClassUtil;
import com.bolt.common.utils.StrUtil;

public class EntityClause<V> extends BaseClause<String,EntityClause,V>  {

    private  String entityName;

    public EntityClause(Class<V>  type) {
        super(null, null, null, type);
        this.owned = createOwnedName(type);
         entityName = ClassUtil.getClassName(type,true);
    }

    @Override
    public String render(boolean addAlias) {
        StringBuffer to = new StringBuffer(60);
        String pattern = templates.get(Ops.ENTITY);
        if(StrUtil.isNotBlank(this.alias) &&  addAlias){
            to.append(StrUtil.indexedFormat(pattern,entityName,this.alias));
        }else{
            to.append(StrUtil.indexedFormat(pattern,entityName,this.owned));
        }
        return to.toString();
    }

    public String getEntityName() {
        return entityName;
    }
}

 